package com.example.spring2304.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class AspectJByAno {

    @Pointcut("execution(* com.example.spring2304.aop.*.*(..))")
    public void myPointCut() {

    }

    @Before("myPointCut()")
    public void myBefore(JoinPoint joinPoint) {
        System.out.println("前置通知myBefore========");
        System.out.println("被增强的目标类：" + joinPoint.getSignature().getName());
    }

    @Around("myPointCut()")
    public Object myAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("环绕通知开始=======");
        Object obj = proceedingJoinPoint.proceed();
        System.out.println("环绕通知结束======");
        return obj;

    }

    @AfterReturning("myPointCut()")
    public void myAfterReturn(JoinPoint joinPoint) {
        System.out.println("后置返回通知======");
    }
    @After("myPointCut()")
    public void myAfter(JoinPoint joinPoint) {
        System.out.println("后置最终通知======");
    }
    @AfterThrowing(value = "myPointCut()",throwing = "e")
    public void myException(JoinPoint joinPoint,Throwable e) {
        System.out.println("异常通知======");
        System.out.println("异常信息：" + e.getMessage());
    }


}
